#!/usr/bin/perl
# index.cgi in emailalert

require './alarms-lib.pl';
&init_config();
&ReadParse();
&header($text{'sending'});
#print 1;
my ($smtp,$receiver,$passwd,$sender,$content);
$smtp=$in{'smtp'};
$receiver=$in{'receiver'};
$passwd=$in{'passwd'};
$sender=$in{'sender'};
$content=$in{'content'};
#print $passwd;

print <<EOF;
 <table class=mode2  border=0 cellspacing=0 cellpadding=1 >
    <tr class=mode1 >
      <td><b>$text{'subject'}:</b></td>
      <td> $text{'test'}</td>
    </tr>
    <tr class=mode2 >
      <td><b>$text{'receiver'}:</b></td>
      <td> $receiver</td>
    </tr>
    <tr class=mode1 >
      <td><b>$text{'smtp'}:</b></td>
      <td> $smtp</td>
    </tr>
    <tr class=mode2 >
      <td><b>$text{'sender'}:</b></td>
      <td>$sender</td>
    </tr>
    <tr class=mode1 >
      <td><b>$text{'content'}:</b></td>
      <td>$content</td>
    </tr>
    </table>
EOF
  

open(HH,">/sysvol/etc/testconf");
print HH "smtp:"."$smtp\n";
print HH "to:"."$receiver\n";
print HH "from:"."$sender\n";
print HH "passwd:"."$passwd\n";
print HH "subject:"."$text{'test'}\n";
print HH "\n";
print HH $content;
close(HH);
my $out=`/sbin/mailsend /sysvol/etc/testconf 2>&1`;

#smtp:$smtp
#to:$receiver
#from:$sender
#passwd:$passwd
#subject:$text{'test'}

#$content

#print $?;
#print $out;
#print $smtp;
if( $? eq 0 ) { 
	$msg= $text{'success'};
} else { 

	if($out =~ /^smtp/) { $msg=&text('smtp_err',$smtp);} 
	elsif($out =~ /^mail/) { $msg=&text('mail_err',$sender);} 
	elsif($out =~ /^to/) { $msg=&text('to_err',$receiver);} 
	elsif($out =~ /^auth/) { $msg=$text{'auth_err'};} 
	else { $msg= $text{'fail'}; }

}
print <<EOF;
<script>
alert("$msg");
top.close();
</script>
EOF
&footer();
